package com.lgy.init;

import com.lgy.comm.Constant;
import com.lgy.core.TaskManager;
import com.lgy.service.ServInfoService;
import com.lgy.utils.FrameSpringBeanUtil;
import com.lgy.utils.FrameTimeUtil;
import org.apache.log4j.Logger;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

/**
 * Created by fengch on 2017/10/9.
 */
public class TaskInit extends HttpServlet {
    private static final Logger LOGGER = Logger.getLogger(TaskInit.class);

    /**
     * 初始化方法
     * @see Servlet#init(ServletConfig)
     */
    public void init(ServletConfig config) throws ServletException {
        LOGGER.info("初始化数据中...");
        long startTime = System.currentTimeMillis();

        //生成服务信息
        ServInfoService servInfoService = (ServInfoService) FrameSpringBeanUtil.getBean(ServInfoService.class);
        servInfoService.registerServer();

        //添加定时任务
        TaskManager taskManager = (TaskManager)FrameSpringBeanUtil.getBean(TaskManager.class);
        taskManager.init();

        LOGGER.info("初始化资源花费" + (System.currentTimeMillis() - startTime) + "毫秒!");
    }
}
